package cn.dg.manager.order.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.dg.manager.common.dao.impl.BaseDaoImpl;
import cn.dg.manager.common.entity.PageEntity;
import cn.dg.manager.order.dao.OrderInfoDao;
import cn.dg.manager.order.entity.OrderEditPageBean;
import cn.dg.manager.order.entity.OrderInfoResultBean;
import cn.dg.manager.order.entity.OrderInfoVO;

@Repository("orderInfoDao")
public class OrderInfoDaoImpl extends BaseDaoImpl implements OrderInfoDao {

	public static final String ORDER_INFO_SQL_PACKAGE = OrderInfoDao.class.getName().concat(".");
	
	/**
	 * 订单列表信息检索
	 */
	public PageEntity<OrderInfoResultBean> findOrderListPagePage(Map<String, Object> params) {
		PageEntity<OrderInfoResultBean> page = new PageEntity<OrderInfoResultBean>();
		int pg = params.get("page") != null ? Integer.parseInt(String.valueOf(params.get("page"))) : START_PAGE_INDEX;
		page.setPageNo(pg);
		page.setParams(params);
		int i = params.get("rows") != null ? Integer.parseInt(String.valueOf(params.get("rows"))) : END_PAGE_INDEX;
		page.setPageSize(i);
		page.setParams(params);
		List<OrderInfoResultBean> goodsTypeList = this.sqlSessionTemplate.selectList(ORDER_INFO_SQL_PACKAGE.concat("findOrderListPagePage"), page);
		page.setResults(goodsTypeList);
		return page;
	}

	/**
	 * 新增订单信息
	 */
	public long insertOrderInfo(OrderInfoVO bean) {
		return (long) this.sqlSessionTemplate.insert(ORDER_INFO_SQL_PACKAGE.concat("insertOrderInfo"), bean);
	}

	/**
	 * 更新订单信息
	 */
	public long updateOrderInfo(OrderInfoVO bean) {
		return (long) this.sqlSessionTemplate.update(ORDER_INFO_SQL_PACKAGE.concat("updateOrderInfo"), bean);
	}

	/**
	 * 根据IDlist 删除订单信息
	 */
	public long deleteOrderInfoByIds(List<String> orderIdList) {
		return (long) this.sqlSessionTemplate.delete(ORDER_INFO_SQL_PACKAGE.concat("deleteGoodsInfoByIdList"), orderIdList);
	}

	/**
	 * 根据订单ID获取订单基本信息
	 */
	public OrderEditPageBean getOrderInfo(String orderId) {
		Map<String, Object> cond = new HashMap<String, Object>();
		cond.put("orderId", orderId);
		return this.sqlSessionTemplate.selectOne(ORDER_INFO_SQL_PACKAGE.concat("getOrderInfo"), cond);
	}
}
